//
//  CDButtonCellCollectionViewCell.m
//  CuriosityDaily3
//
//  Created by 安林 on 16/9/23.
//  Copyright © 2016年 theBestTeam. All rights reserved.
//

#import "CDButtomCell.h"

@interface CDButtomCell()
@property (nonatomic, weak) UIImageView* iconView;
@property (nonatomic, weak) UILabel* nameLabel;

@end

@implementation CDButtomCell
-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
   self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self setupUI];
    }
    return self;
}
-(void)setButtomBtnType:(CDButtomBtnType *)ButtomBtnType{
    _ButtomBtnType = ButtomBtnType;
    self.iconView.image = [UIImage imageNamed:ButtomBtnType.icon];
    self.nameLabel.text = ButtomBtnType.name;
}
- (void)setupUI{
    UIImageView* iconView = [[UIImageView alloc] init];
    iconView.image = [UIImage imageNamed:@"menu_home@2x.png"];
    [self.contentView addSubview:iconView];
    // name
    UILabel* nameLabel = [[UILabel alloc] init];
    nameLabel.textColor = [UIColor whiteColor];
    nameLabel.text = @"安林";
    nameLabel.font = [UIFont systemFontOfSize:14];
    
    UIButton *rightBtn = [[UIButton alloc]init];
    rightBtn.frame = CGRectMake(self.bounds.size.width / 2, 0, self.bounds.size.width / 2, 50);
    [rightBtn addTarget:self action:@selector(rightBtnClick) forControlEvents:UIControlEventTouchUpInside];
    [self.contentView addSubview:rightBtn];
    
    
    [self.contentView addSubview:nameLabel];
    // 自动布局
    [iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.offset(10);
        make.left.offset(30);
        make.width.height.offset(35);
    }];
    [nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(iconView);
        make.left.equalTo(iconView.mas_right).offset(5);
    }];
    
    self.iconView = iconView;
    self.nameLabel = nameLabel;

}
-(void)rightBtnClick{
    [[NSNotificationCenter defaultCenter] postNotificationName:@"rightBtnClick" object:nil];
}
@end
